import 'dart:convert';
import 'package:flutter/widgets.dart';
import 'package:x3_base_core/base_models/base_model_asT.dart';
import 'package:x3_component_core/models/base_custom_checkbox_tile_model.dart';

class BaseSubLevelMultiSelectorModel {
  final String title;
  final String id;
  final String inputApi;
  final Map<String, dynamic> params;
  bool isAll;
  List<BaseCustomCheckboxListTileModel> children = [];
  Set<int> selectedChildrenKey = {};

  BaseSubLevelMultiSelectorModel({
    @required this.title,
    @required this.id,
    @required this.inputApi,
    this.isAll = false,
    this.children = const [],
    this.params = const {},
  }) : assert(title != null);

  factory BaseSubLevelMultiSelectorModel.fromJson(Map<String, dynamic> jsonRes) {
    return jsonRes == null
        ? null
        : BaseSubLevelMultiSelectorModel(
            title: asT<String>(jsonRes['title']),
            id: asT<String>(jsonRes['id']),
            inputApi: asT<String>(jsonRes['inputApi']),
            isAll: asT<bool>(jsonRes['isAll']),
            children: asT<List<BaseCustomCheckboxListTileModel>>(jsonRes['children']),
            params: asT<Map<String, dynamic>>(jsonRes['params']),
          );
  }

  Map<String, dynamic> toJson() => <String, dynamic>{
        'title': title,
        'id': id,
        'inputApi': inputApi,
        'isAll': isAll,
        'params': params,
        'children': children,
      };

  @override
  String toString() {
    return json.encode(this);
  }
}
